package com.java.base.exercise.disruptor;

import com.lmax.disruptor.EventTranslatorOneArg;
import com.lmax.disruptor.RingBuffer;

/**
 * @Author RenPu
 * @Date 2023/10/25 15:01
 * @Version 1.0
 * @Description: 消息生产者将消息包装为：
 *                       event类型进行存储,
 *                       计算sequence,
 *                       同时维护event引用指向新对象
 **/
public class LongEventProducterWithTranslator {

    private final RingBuffer<LongEvent> ringBuffer;

    public LongEventProducterWithTranslator(RingBuffer<LongEvent> ringBuffer) {
        this.ringBuffer = ringBuffer;
    }

    EventTranslatorOneArg<LongEvent,Long> translatorOneArg= new EventTranslatorOneArg<LongEvent,Long>() {


        @Override
        public void translateTo(LongEvent longEvent, long l, Long aLong) {
            longEvent.setValue(aLong);
        }
    };

    public void onData(Long data){
        ringBuffer.publishEvent(translatorOneArg,data);

    }

}
